#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<string>
#include<unordered_map>
#include<algorithm>
using namespace std;


class Node {
public:
    int val;
    Node* next;
    Node* random;

    Node(int _val) {
        val = _val;
        next = nullptr;
        random = nullptr;
    }
};

class Solution {
public:
    bool isAnagram(string s, string t) {
        if (s.size() != t.size()) return false;
        int hash[26] = { 0 };
        for (int i = 0; i < s.size(); i++) hash[s[i] - 'a']++;
        for (int i = 0; i < t.size(); i++) {
            hash[t[i] - 'a']--;
            if (hash[t[i] - 'a'] < 0) return false;
        }
        return true;
    }
};

class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        unordered_map<string, vector<string>> hashMap;
        for (int i = 0; i < strs.size(); i++) {
            string key = strs[i];
            sort(key.begin(), key.end());
            hashMap[key].push_back(strs[i]);
        }
        vector<vector<string>> ret;
        for (auto [a, b] : hashMap) {
            ret.push_back(b);
        }
        return ret;
    }
};

class Solution {
public:
    Node* copyRandomList(Node* head) {
        unordered_map<Node*, Node*> hashMap;
        Node* cur = head, * Head = nullptr, * Tail = nullptr;
        while (cur) {
            Node* copy = new Node(cur->val);
            hashMap[cur] = copy;
            if (Head == nullptr) {
                Head = Tail = copy;
            }
            else {
                Tail->next = copy;
                Tail = Tail->next;
            }
            cur = cur->next;
        }
        cur = head;
        while (cur) {
            if (cur->random == nullptr) hashMap[cur]->random == nullptr;
            else hashMap[cur]->random = hashMap[cur->random];
            cur = cur->next;
        }
        return Head;
    }
};